/**
 *
 */
package com.amir.common.weight;

import android.graphics.Color;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;
import android.view.View.OnClickListener;

/**
 * @author justKeepmoving
 * @date 2015年4月15日下午4:33:44
 */
public class MyClickableSpan extends ClickableSpan {
    private boolean hasUnderLine;
    private OnClickListener listener;
    private int color;

    public void setColor(int color) {
        this.color = color;
    }

    public MyClickableSpan() {
        this(false);
    }

    public MyClickableSpan(int color) {
        this.color = color;
    }

    public MyClickableSpan(boolean hasUnderLine) {
        this.hasUnderLine = hasUnderLine;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        if (color == 0) {
            color = Color.GRAY;
        }
        ds.setColor(color);
        ds.setUnderlineText(hasUnderLine);
    }

    public void setOnClickListener(OnClickListener listener) {
        this.listener = listener;
    }

    @Override
    public void onClick(View v) {
        if (listener != null)
            listener.onClick(v);
    }
}
